package com.th.supcom.pds.phamapply.client.widget.checkdispense;

import com.extjs.gxt.ui.client.Style.LayoutRegion;
import com.extjs.gxt.ui.client.util.Margins;
import com.extjs.gxt.ui.client.widget.LayoutContainer;
import com.extjs.gxt.ui.client.widget.layout.BorderLayout;
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
import com.th.supcom.pds.phamapply.client.widget.phamdispense.PhamDispenseFields;

/**
 * InpPhamDispenseDetail主面板.
 * 
 * 住院摆药明细表.
 */
public class InpCheckDispenseMainPanel extends LayoutContainer
{
    private InpCheckDispenseButtons m_buttons;
    private PhamDispenseFields m_fields;
    private InpCheckDispenseCollectGrid m_inpCheckDispenseCollectGrid;
    private InpCheckDispenseDetailGrid m_inpCheckDispenseDetailGrid;
    private InpCheckDispenseNurseUnitInfoGrid m_inpChecknurseUnitInfoGrid;
    private InpCheckDispenseConditionMain m_inpCheckDispenseConditionMain;
    private InpCheckDispenseTabPanel m_inpCheckDispenseTabPanel;
    private InpCheckDispenseAction m_action;
    private QueryDispenseByBarCodePanel m_barCodePanel;
    private KeyNavListener m_keyNavListener;

    public InpCheckDispenseMainPanel ()
    {
        initUI ();
        initAction ();
        initListeners ();
        initData ();
    }

    /**
     * 初始化事件
     */
    private void initAction ()
    {
        m_action = new InpCheckDispenseAction ();
        m_action.setInpCheckDispenseNurseUnitInfoGrid (m_inpChecknurseUnitInfoGrid);
        m_action.setInpCheckDispenseDetailGrid (m_inpCheckDispenseDetailGrid);
        m_action.setCollectGrid (m_inpCheckDispenseCollectGrid);
        m_action.setFields (m_fields);
        m_action.setButtons (m_buttons);
    }

    /**
     * 初始化数据
     */
    private void initData ()
    {
        m_action.initData ();
    }

    /**
     * 初始化事件监听
     */
    private void initListeners ()
    {
        InpCheckDispenseListener m_inpCheckDispenseListener;
        m_inpCheckDispenseListener = new InpCheckDispenseListener ();
        m_inpCheckDispenseListener.setInpCheckDispenseAction (m_action);
        m_inpCheckDispenseListener.setInpCheckDispenseButtons (m_buttons);
        m_inpCheckDispenseListener.setCheckDispenseNurseUnitInfoGrid (m_inpChecknurseUnitInfoGrid);
        m_inpCheckDispenseListener.setPhamDispenseFields (m_fields);
        m_inpCheckDispenseListener.initListeners ();
        
        m_keyNavListener = new KeyNavListener ();
        m_keyNavListener.addEnterKeyListener (this);
        m_keyNavListener.setAction (m_action);
    }

    /**
     * 初始化UI
     */
    private void initUI ()
    {
        this.setLayout (new BorderLayout ());

        createButtons ();
        createFields ();
        createGrids ();
        createPanels ();

        BorderLayoutData centerData = new BorderLayoutData (LayoutRegion.CENTER);
        centerData.setMargins (new Margins (2, 0, 2, 0));
        BorderLayoutData westData = new BorderLayoutData (LayoutRegion.WEST, 200);
        westData.setMargins (new Margins (2, 5, 2, 0));

        add (m_inpCheckDispenseTabPanel, centerData);
        add (m_inpCheckDispenseConditionMain, westData);
    }

    /**
     * 初始化Buttons
     */
    private void createButtons ()
    {
        m_buttons = new InpCheckDispenseButtons ();
    }

    /**
     * 初始化Fields
     */
    private void createFields ()
    {
        m_fields = new PhamDispenseFields ();
        //初始化的时候默认焦点设置在二维码输入框上
        m_fields.getBarCode ().focus ();
    }

    /**
     * 初始化Panel
     */
    private void createPanels ()
    {
        m_barCodePanel = new QueryDispenseByBarCodePanel ();
        m_barCodePanel.setFields (m_fields);
        m_barCodePanel.initUI ();
        
        m_inpCheckDispenseConditionMain = new InpCheckDispenseConditionMain();
        m_inpCheckDispenseConditionMain.setInpCheckDispenseNurseUnitInfoGrid (m_inpChecknurseUnitInfoGrid);
        m_inpCheckDispenseConditionMain.setBarCodePanel (m_barCodePanel);
        m_inpCheckDispenseConditionMain.initUI ();

        m_inpCheckDispenseTabPanel = new InpCheckDispenseTabPanel ();
        m_inpCheckDispenseTabPanel.setInpCheckDispenseButtons (m_buttons);
        m_inpCheckDispenseTabPanel.setInpCheckDispenseCollectGrid (m_inpCheckDispenseCollectGrid);
        m_inpCheckDispenseTabPanel.setInpCheckDispenseDetailGrid (m_inpCheckDispenseDetailGrid);
        m_inpCheckDispenseTabPanel.initUI ();
        
        
    }

    /**
     * 初始化Grid
     */
    private void createGrids ()
    {
        m_inpCheckDispenseCollectGrid = new InpCheckDispenseCollectGrid ();
        m_inpCheckDispenseDetailGrid = new InpCheckDispenseDetailGrid ();
        m_inpChecknurseUnitInfoGrid = new InpCheckDispenseNurseUnitInfoGrid ();
    }

}